package yunwo.cn.yzstation.model;

import android.content.Context;
import android.content.SharedPreferences;
import android.util.Log;
import android.widget.Toast;

import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.zhy.http.okhttp.OkHttpUtils;
import com.zhy.http.okhttp.callback.StringCallback;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import okhttp3.Call;
import yunwo.cn.yzstation.api.HttpManager;
import yunwo.cn.yzstation.api.IcostModel;
import yunwo.cn.yzstation.api.okapi.BaoFeiCallBack;
import yunwo.cn.yzstation.api.okapi.GLCallBack;
import yunwo.cn.yzstation.base.Yzapp;
import yunwo.cn.yzstation.bean.BaoFeiBean;
import yunwo.cn.yzstation.bean.PopupBean;
import yunwo.cn.yzstation.config.MyConstants;
import yunwo.cn.yzstation.view.activity.OrderActivity;

/**
 * Created by lao on 2017/9/11.
 */
public class CostModel {
    OrderActivity mOrderActivity;
    IcostModel mIcostModel;
    private SharedPreferences mBaoFeiJiFei_sp;

    public CostModel(OrderActivity orderActivity, IcostModel icostModel) {
        this.mOrderActivity = orderActivity;
        this.mIcostModel = icostModel;
        mBaoFeiJiFei_sp = mOrderActivity.getSharedPreferences("feiyong", Context.MODE_PRIVATE);
    }

    public void getBaoFei(String s) {


/*
        Map<String, Object> map = new HashMap<>();
        map.put("feeWay",mBaoFeiJiFei_sp.getString("dictValue", ""));
        map.put("standardVal", s);

        HttpManager.hpptPostString3(MyConstants.Baofei, map).execute(new BaoFeiCallBack(BaoFeiBean.class,mOrderActivity,false){
            @Override
            public void myError(Call call, Exception e, int id) {
                Log.d("222222222222",e.toString() + "");
            }

            @Override
            public void onResponse(BaoFeiBean response, int id) {
                if (response.getCode() == 200) {
                    mIcostModel.getBaoFeiSuccess(response.getData());
                }
            }
        });*/

    }

    public void getProcuration(String s) {
      /*  final Map<String, Object> map = new HashMap<>();
        map.put("feeWay",mBaoFeiJiFei_sp.getString("daishou", ""));
        map.put("standardVal", s);

        HttpManager.hpptPostString3(MyConstants.Procuration,map).execute(new GLCallBack() {
            @Override
            public void onResponseT(String result, int code, String msg, int id) {
                if (code == 200) {
                    if (!result.equals("")) {
                        Log.d("dddd", result);
//                        mIcostModel.getProcurationSuccess(result);
                    }
                }
                else {
                    Toast.makeText(mOrderActivity, code + msg+"代收"+mBaoFeiJiFei_sp.getString("daishou", ""), Toast.LENGTH_SHORT).show();
                }
            }

            @Override
            public void onError(Call call, Exception e, int id) {
                Toast.makeText(mOrderActivity, e.toString(), Toast.LENGTH_SHORT).show();

            }
        });*/
    }

    public void requestPopupCon(String type, String data) {
        Map<String, Object> map = new HashMap<>();
        switch (type) {
            case "1":
                map.put("name", data);
                break;
            case "2":
                map.put("phone", data);
                break;
            case "3":
                map.put("address", data);
                break;
        }
        HttpManager.hpptPostString3(MyConstants.SearchConsignor, map).execute(new GLCallBack() {
            @Override
            public void onResponseT(String result, int code, String msg, int id) {
                if (code == 200) {
                    if (!result.equals("")) {

                        List<PopupBean.DataBean> PopupBean = new Gson().fromJson(result, new TypeToken<List<PopupBean.DataBean>>() {
                        }.getType());
                        mIcostModel.requestPopupConSuccess(PopupBean);
                    }
                }
                else {

                }
            }

            @Override
            public void onError(Call call, Exception e, int id) {

            }
        });
    }
}
/*new BaoFeiCallBack(BaoFeiBean.class,mOrderActivity,false){
            @Override
            public void myError(Call call, Exception e, int id) {
                super.myError(call, e, id);
            }

            @Override
            public void onResponse(BaoFeiBean response, int id) {
                if (response.getCode() == 200) {
                    mIcostModel.getProcurationSuccess(response.getData());
                }
            }
        }*/